package com.example.test.controller;

import com.example.test.entity.Look;
import com.example.test.service.LookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/products")
@CrossOrigin
public class LookController {

    @Autowired
    private LookService lookService;

    @PostMapping("/lookmes")
    public ResponseEntity<?> recordLook(@RequestBody Look look) {
        int result = lookService.createLook(look);
        if (result == 1) {
            return ResponseEntity.ok().build();
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
        }
    }

    @GetMapping("/allLooks")
    public ResponseEntity<List<Look>> getAllLooks() {
        List<Look> allLooks = lookService.getAllLooks();
        return ResponseEntity.ok().body(allLooks);
    }

    @GetMapping("/lastSixLooks")
    public ResponseEntity<List<Look>> getLastSixLooks() {
        List<Look> lastSixLooks = lookService.getLastSixLooks();
        return ResponseEntity.ok().body(lastSixLooks);
    }
}
